package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketFootprint;
import com.cskaoyan.market.service.MarketAdminFootprintService;
import com.cskaoyan.market.service.impl.MarketAdminFootprintServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admin/footprint/*")
public class AdminFootprintController extends HttpServlet {
    MarketAdminFootprintService service = new MarketAdminFootprintServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String requestURI = req.getRequestURI();
        String op = requestURI.replace("/admin/footprint/", "");

        if ("list".equals(op)) {
            list(req, resp);
        }
    }

    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        // 获取请求
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        String userId = req.getParameter("userId");
        String goodsId = req.getParameter("goodsId");
        String sort = req.getParameter("sort");
        String order = req.getParameter("order");

        List<MarketFootprint> marketFootprints = service.list(page,limit,userId,goodsId,sort,order);

        Object o = ResponseUtil.okList(marketFootprints);
        String s = JacksonUtil.writeValueAsString(o);

        resp.getWriter().println(s);
    }
}
